<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Code example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
</head>
<style type="text/css">
html body { padding:0; margin:0 } 
.code-base
{
	color:#c6c9c9; white-space:pre;
	background-color:#2f3d39;
	padding:20px 0px 20px 40px; margin:0;
}
.classname { color:#17e0ec; }
.keyword { color:#528eef; }
.reserved { color:#8a66de; }
.xml { color:#f0b93c; }
.operator { color:#ffffff; }
.asdoc-comment { color:#b3f03c; font-style:italic; }
.asdoc-keyword { color:#e18e51; font-style:italic; }
.block-comment { color:#798161; }
.line-comment { color:#61816d; font-style:italic; }
.number { color:#ee86f1; }
.regexp { color:#e21c99; }
.string { color:#e36352; font-weight:bold; }
</style>
<body><pre class="code-base"><span class="keyword">package</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3 <br/><span class="operator">{</span><br/>    <span class="keyword">import</span> flash<span class="operator">.</span>utils<span class="operator">.</span><span class="classname">Dictionary</span><span class="operator">;</span><br/>    <br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>resources<span class="operator">.</span>AS3ParserSettings<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>ASDocCommentSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>ASDocKeywordSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>BlockCommentSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>DefaultSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>LineCommentSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>LineEndSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>NumberSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>OperatorSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>RegExpSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>StringSink<span class="operator">;</span><br/>    <span class="keyword">import</span> org<span class="operator">.</span>wvxvws<span class="operator">.</span>parsers<span class="operator">.</span>as3<span class="operator">.</span>sinks<span class="operator">.</span>WhiteSpaceSink<span class="operator">;</span><br/>    <br/>    <span class="asdoc-comment">/**</span><br/>     <span class="asdoc-comment">* Note that in order for this class to compile without warnings, you would</span><br/>     <span class="asdoc-comment">* have to edit flex-config.xml in your SDK.</span><br/>     <span class="asdoc-comment">* Find this line:</span><br/>     <span class="asdoc-comment">* &lt;pre&gt;&amp;lt;warn-unlikely-function-value&amp;gt;true&amp;lt;/warn-unlikely-function-value&amp;gt;&lt;/pre&gt;</span><br/>     <span class="asdoc-comment">* and change it to:</span><br/>     <span class="asdoc-comment">* &lt;pre&gt;&amp;lt;warn-unlikely-function-value&amp;gt;false&amp;lt;/warn-unlikely-function-value&amp;gt;&lt;/pre&gt;</span><br/>     <span class="asdoc-comment">* And this is how you should be working in general ;)</span><br/>     <span class="asdoc-comment">* Alternatively you could add this parameter elsewhere in your project setup:</span><br/>     <span class="asdoc-comment">* &lt;pre&gt;-warn-unlikely-function-value=false&lt;/pre&gt;</span><br/>     <span class="asdoc-comment">* </span><br/>     <span class="asdoc-comment">* </span><span class="asdoc-keyword">@author</span> <span class="asdoc-comment">wvxvw</span><br/>     <span class="asdoc-comment">*/</span><br/>    <span class="keyword">public</span> <span class="keyword">class</span> AS3Sinks<br/>    <span class="operator">{</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onASDocComment<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onASDocKeyword<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onBlockComment<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onLineComment<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onString<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onNumber<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onRegExp<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onXML<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onOperator<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onKeyword<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onWhiteSpace<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onDefault<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onCharacter<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onLine<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onClassName<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onError<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <span class="keyword">public</span> <span class="keyword">var</span> onReserved<span class="operator">:</span><span class="classname">Function</span><span class="operator">;</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> line<span class="operator">():</span><span class="classname">int</span> <span class="operator">{</span> <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_line<span class="operator">;</span> <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> column<span class="operator">():</span><span class="classname">int</span> <span class="operator">{</span> <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_column<span class="operator">;</span> <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> source<span class="operator">():</span><span class="classname">String</span> <span class="operator">{</span> <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_source<span class="operator">;</span> <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> settings<span class="operator">():</span>AS3ParserSettings<br/>        <span class="operator">{</span><br/>            <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_settings<span class="operator">;</span><br/>        <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> word<span class="operator">():</span><span class="classname">String</span> <span class="operator">{</span> <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_word<span class="operator">;</span> <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> currentSink<span class="operator">():</span>ISink <span class="operator">{</span> <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_currentSink<span class="operator">;</span> <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> hasError<span class="operator">():</span><span class="classname">Boolean</span> <span class="operator">{</span> <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_hasError<span class="operator">;</span> <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> <span class="keyword">get</span> collectedText<span class="operator">():</span><span class="classname">String</span> <span class="operator">{</span> <span class="keyword">return</span> <span class="reserved">this</span><span class="operator">.</span>_collectedText<span class="operator">;</span> <span class="operator">}</span><br/>        <br/>        <span class="keyword">private</span> <span class="keyword">var</span> _line<span class="operator">:</span><span class="classname">int</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _column<span class="operator">:</span><span class="classname">int</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _lines<span class="operator">:</span>Vector<span class="operator">.&lt;</span><span class="classname">String</span><span class="operator">&gt;</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="operator">&lt;</span><span class="classname">String</span><span class="operator">&gt;[];</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _source<span class="operator">:</span><span class="classname">String</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _lastLineEnd<span class="operator">:</span><span class="classname">int</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _word<span class="operator">:</span><span class="classname">String</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _settings<span class="operator">:</span>AS3ParserSettings<span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _currentSink<span class="operator">:</span>ISink<span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _hasError<span class="operator">:</span><span class="classname">Boolean</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _error<span class="operator">:</span>AS3ReaderError<span class="operator">;</span><br/>        <br/>        <span class="keyword">private</span> <span class="keyword">const</span> _stack<span class="operator">:</span>SinksStack <span class="operator">=</span> <span class="keyword">new</span> SinksStack<span class="operator">();</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _collectedText<span class="operator">:</span><span class="classname">String</span> <span class="operator">=</span> <span class="string">""</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _collectWhiteSpaces<span class="operator">:</span><span class="classname">Boolean</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _collectWords<span class="operator">:</span><span class="classname">Boolean</span><span class="operator">;</span><br/>        <span class="keyword">private</span> <span class="keyword">var</span> _collectLineEnds<span class="operator">:</span><span class="classname">Boolean</span><span class="operator">;</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> AS3Sinks<span class="operator">()</span><br/>        <span class="operator">{</span><br/>            <span class="reserved">super</span><span class="operator">();</span><br/>            <span class="reserved">this</span><span class="operator">.</span>buildDictionary<span class="operator">();</span><br/>        <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> read<span class="operator">(</span>source<span class="operator">:</span><span class="classname">String</span><span class="operator">,</span> settings<span class="operator">:</span>AS3ParserSettings<span class="operator">):</span><span class="classname">void</span><br/>        <span class="operator">{</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_source <span class="operator">=</span> source<span class="operator">;</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_settings <span class="operator">=</span> settings<span class="operator">;</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_column <span class="operator">=</span> <span class="number">0</span><span class="operator">;</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_lastLineEnd <span class="operator">=</span> <span class="number">0</span><span class="operator">;</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_line <span class="operator">=</span> <span class="number">0</span><span class="operator">;</span><br/>            <span class="line-comment">// TODO: whoops, forgot these :) have to count them and collect!</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_lines<span class="operator">.</span>splice<span class="operator">(</span><span class="number">0</span><span class="operator">,</span> <span class="reserved">this</span><span class="operator">.</span>_lines<span class="operator">.</span>length<span class="operator">);</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_word <span class="operator">=</span> <span class="string">""</span><span class="operator">;</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_collectedText <span class="operator">=</span> <span class="string">""</span><span class="operator">;</span><br/>            <span class="reserved">this</span><span class="operator">.</span>buildDictionary<span class="operator">();</span><br/>            <span class="reserved">this</span><span class="operator">.</span>loopSinks<span class="operator">();</span><br/>        <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> advanceColumn<span class="operator">(</span>character<span class="operator">:</span><span class="classname">String</span><span class="operator">):</span><span class="classname">void</span><br/>        <span class="operator">{</span><br/>            <span class="keyword">if</span> <span class="operator">(!</span><span class="reserved">this</span><span class="operator">.</span>_hasError<span class="operator">)</span><br/>            <span class="operator">{</span><br/>                <span class="reserved">this</span><span class="operator">.</span>_column<span class="operator">++;</span><br/>                <span class="keyword">if</span> <span class="operator">(</span><span class="reserved">this</span><span class="operator">.</span>onCharacter<span class="operator">)</span> <span class="reserved">this</span><span class="operator">.</span>onCharacter<span class="operator">(</span>character<span class="operator">);</span><br/>            <span class="operator">}</span><br/>        <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> appendCollectedText<span class="operator">(</span>text<span class="operator">:</span><span class="classname">String</span><span class="operator">):</span><span class="classname">void</span><br/>        <span class="operator">{</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_collectedText <span class="operator">+=</span> text<span class="operator">;</span><br/>        <span class="operator">}</span><br/>        <br/>        <span class="keyword">public</span> <span class="keyword">function</span> reportError<span class="operator">(</span>message<span class="operator">:</span><span class="classname">String</span><span class="operator">):</span><span class="classname">void</span><br/>        <span class="operator">{</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_hasError <span class="operator">=</span> <span class="reserved">true</span><span class="operator">;</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_error <span class="operator">=</span> <span class="keyword">new</span> AS3ReaderError<span class="operator">(</span>message<span class="operator">,</span> <span class="reserved">this</span><span class="operator">.</span>_line<span class="operator">,</span> <span class="reserved">this</span><span class="operator">.</span>_column<span class="operator">);</span><br/>            <span class="keyword">if</span> <span class="operator">(</span><span class="reserved">this</span><span class="operator">.</span>onError <span class="operator">&amp;&amp;</span> <span class="reserved">this</span><span class="operator">.</span>onError<span class="operator">(</span><span class="reserved">this</span><span class="operator">.</span>_error<span class="operator">))</span><br/>                <span class="reserved">this</span><span class="operator">.</span>_hasError <span class="operator">=</span> <span class="reserved">false</span><span class="operator">;</span><br/>            <span class="keyword">else</span> <span class="keyword">throw</span> <span class="reserved">this</span><span class="operator">.</span>_error<span class="operator">;</span><br/>        <span class="operator">}</span><br/>        <br/>        <span class="keyword">private</span> <span class="keyword">function</span> buildDictionary<span class="operator">():</span><span class="classname">void</span><br/>        <span class="operator">{</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_stack<span class="operator">.</span>clear<span class="operator">();</span><br/>            <span class="reserved">this</span><span class="operator">.</span>_stack<span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> StringSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> RegExpSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> WhiteSpaceSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> LineCommentSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> BlockCommentSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> ASDocCommentSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> LineEndSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> NumberSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> OperatorSink<span class="operator">())</span><br/>                <span class="operator">.</span>add<span class="operator">(</span><span class="keyword">new</span> DefaultSink<span class="operator">());</span><br/>        <span class="operator">}</span><br/>        <br/>        <span class="keyword">private</span> <span class="keyword">function</span> loopSinks<span class="operator">():</span><span class="classname">void</span><br/>        <span class="operator">{</span><br/>            <span class="keyword">var</span> nextSink<span class="operator">:</span>ISink<span class="operator">;</span><br/>            <span class="keyword">while</span> <span class="operator">(</span>nextSink <span class="operator">=</span> <span class="reserved">this</span><span class="operator">.</span>_stack<span class="operator">.</span>next<span class="operator">())</span><br/>            <span class="operator">{</span><br/>                <span class="keyword">if</span> <span class="operator">(</span>nextSink<span class="operator">.</span>isSinkStart<span class="operator">(</span><span class="reserved">this</span><span class="operator">)</span> <span class="operator">&amp;&amp;</span> nextSink<span class="operator">.</span>read<span class="operator">(</span><span class="reserved">this</span><span class="operator">))</span><br/>                    <span class="reserved">this</span><span class="operator">.</span>_stack<span class="operator">.</span>reset<span class="operator">();</span><br/>            <span class="operator">}</span><br/>        <span class="operator">}</span><br/>    <span class="operator">}</span><br/><span class="operator">}</span></pre></body>
</html>